<?php

    require_once( 'Database.php' );

    use PHPK\Database;

    $oDbh = new Database( dirname( dirname( __FILE__ ) ) . '/pdfbldr.db' );
    $oPdo = $oDbh->pdo;
    $oSql = $oPdo->prepare( 'SELECT content, saved FROM pdfbldr WHERE docid = :docid' );

    $strDocID = !empty( $_GET[ 'docid' ] ) ? $_GET[ 'docid' ] : '';
    $strContent = '';
    $nSaved = 0;
    $arResult = array();

    $oSql->bindParam( ':docid', $strDocID );
    $arResult[ 'load' ] = $oSql->execute() ? true : false;

    $oSql->bindColumn( 'content', $strContent );
    $oSql->bindColumn( 'saved', $nSaved );
    $oSql->fetch();

    date_default_timezone_set( 'Asia/Calcutta' );    

    $arResult[ 'content' ] = $strContent;
    $arResult[ 'docid' ] = $strDocID;
    $arResult[ 'saved' ] = date( 'm/d/y g:i:s a', $nSaved );

    header( 'Content-Type: application/json' );
    print json_encode( $arResult );

?>
